home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gxdevice.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  21.8 KB  |  537 lines

  1. /* Copyright (C) 1997, 1998, 1999, 2000 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gxdevice.h,v 1.4 2000/09/19 19:00:36 lpd Exp $ */
  20. /* Definitions for device implementors */
  21.  
  22. #ifndef gxdevice_INCLUDED
  23. #  define gxdevice_INCLUDED
  24.  
  25. #include "stdio_.h"        /* for FILE */
  26. #include "gxdevcli.h"
  27. #include "gsfname.h"
  28. #include "gsparam.h"
  29. /*
  30.  * Many drivers still use gs_malloc and gs_free, so include the interface
  31.  * for these.  (Eventually they should go away.)
  32.  */
  33. #include "gsmalloc.h"
  34. /*
  35.  * Similarly, quite a few drivers reference stdout and/or stderr.
  36.  * (Eventually these references must go away.)
  37.  */
  38. #include "gxstdio.h"
  39.  
  40. /*
  41.  * NOTE: if you write code that creates device instances (either with
  42.  * gs_copydevice or by allocating them explicitly), allocates device
  43.  * instances as either local or static variables (actual instances, not
  44.  * pointers to instances), or sets the target of forwarding devices, please
  45.  * read the documentation in gxdevcli.h about memory management for devices.
  46.  * The rules for doing these things changed substantially in release 5.68,
  47.  * in a non-backward-compatible way, and unfortunately we could not find a
  48.  * way to make the compiler give an error at places that need changing.
  49.  */
  50.  
  51. /* ---------------- Auxiliary types and structures ---------------- */
  52.  
  53. /* Define default pages sizes. */
  54. /* U.S. letter paper (8.5" x 11"). */
  55. #define DEFAULT_WIDTH_10THS_US_LETTER 85
  56. #define DEFAULT_HEIGHT_10THS_US_LETTER 110
  57. /* A4 paper (210mm x 297mm).  The dimensions are off by a few mm.... */
  58. #define DEFAULT_WIDTH_10THS_A4 83
  59. #define DEFAULT_HEIGHT_10THS_A4 117
  60. /* Choose a default.  A4 may be set in the makefile. */
  61. #ifdef A4
  62. #  define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_A4
  63. #  define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_A4
  64. #else
  65. #  define DEFAULT_WIDTH_10THS DEFAULT_WIDTH_10THS_US_LETTER
  66. #  define DEFAULT_HEIGHT_10THS DEFAULT_HEIGHT_10THS_US_LETTER
  67. #endif
  68.  
  69. /* ---------------- Device structure ---------------- */
  70.  
  71. /*
  72.  * To insulate statically defined device templates from the
  73.  * consequences of changes in the device structure, the following macros
  74.  * must be used for generating initialized device structures.
  75.  *
  76.  * The computations of page width and height in pixels should really be
  77.  *      ((int)(page_width_inches*x_dpi))
  78.  * but some compilers (the Ultrix 3.X pcc compiler and the HPUX compiler)
  79.  * can't cast a computed float to an int.  That's why we specify
  80.  * the page width and height in inches/10 instead of inches.
  81.  *
  82.  * Note that the macro is broken up so as to be usable for devices that
  83.  * add further initialized state to the generic device.
  84.  * Note also that the macro does not initialize procs, which is
  85.  * the next element of the structure.
  86.  */
  87. #define std_device_part1_(devtype, ptr_procs, dev_name, stype, open_init)\
  88.     sizeof(devtype), ptr_procs, dev_name,\
  89.     0 /*memory*/, stype, 0 /*stype_is_dynamic*/, 0 /*finalize*/,\
  90.     { 0 } /*rc*/, 0 /*retained*/, open_init() /*is_open, max_fill_band*/
  91.     /* color_info goes here */
  92. /*
  93.  * The MetroWerks compiler has some bizarre bug that produces a spurious
  94.  * error message if the width and/or height are defined as 0 below,
  95.  * unless we use the +/- workaround in the next macro.
  96.  */
  97. #define std_device_part2_(width, height, x_dpi, y_dpi)\
  98.     { gx_no_color_index, gx_no_color_index }, width, height,\
  99.     { (((width) * 72.0 + 0.5) - 0.5) / (x_dpi),\
  100.       (((height) * 72.0 + 0.5) - 0.5) / (y_dpi) },\
  101.     { 0, 0, 0, 0 }, 0/*false*/, { x_dpi, y_dpi }, { x_dpi, y_dpi }
  102. /* offsets and margins go here */
  103. #define std_device_part3_()\
  104.     0, 0, 1, 0/*false*/, 0/*false*/, 0/*false*/,\
  105.     { gx_default_install, gx_default_begin_page, gx_default_end_page }
  106. /*
  107.  * We need a number of different variants of the std_device_ macro simply
  108.  * because we can't pass the color_info or offsets/margins
  109.  * as macro arguments, which in turn is because of the early macro
  110.  * expansion issue noted in stdpre.h.  The basic variants are:
  111.  *      ...body_with_macros_, which uses 0-argument macros to supply
  112.  *        open_init, color_info, and offsets/margins;
  113.  *      ...full_body, which takes 12 values (6 for dci_values,
  114.  *        6 for offsets/margins);
  115.  *      ...color_full_body, which takes 9 values (3 for dci_color,
  116.  *        6 for margins/offset).
  117.  *      ...std_color_full_body, which takes 7 values (1 for dci_std_color,
  118.  *        6 for margins/offset).
  119.  *      
  120.  */
  121. #define std_device_body_with_macros_(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, open_init, dci_macro, margins_macro)\
  122.     std_device_part1_(dtype, pprocs, dname, stype, open_init),\
  123.     dci_macro(),\
  124.     std_device_part2_(w, h, xdpi, ydpi),\
  125.     margins_macro(),\
  126.     std_device_part3_()
  127.  
  128. #define std_device_std_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi)\
  129.     std_device_body_with_macros_(dtype, pprocs, dname, stype,\
  130.       w, h, xdpi, ydpi,\
  131.       open_init_closed, dci_black_and_white_, no_margins_)
  132.  
  133. #define std_device_std_body(dtype, pprocs, dname, w, h, xdpi, ydpi)\
  134.     std_device_std_body_type(dtype, pprocs, dname, 0, w, h, xdpi, ydpi)
  135.  
  136. #define std_device_std_body_type_open(dtype, pprocs, dname, stype, w, h, xdpi, ydpi)\
  137.     std_device_body_with_macros_(dtype, pprocs, dname, stype,\
  138.       w, h, xdpi, ydpi,\
  139.       open_init_open, dci_black_and_white_, no_margins_)
  140.  
  141. #define std_device_std_body_open(dtype, pprocs, dname, w, h, xdpi, ydpi)\
  142.     std_device_std_body_type_open(dtype, pprocs, dname, 0, w, h, xdpi, ydpi)
  143.  
  144. #define std_device_full_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)\
  145.     std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
  146.     dci_values(ncomp, depth, mg, mc, dg, dc),\
  147.     std_device_part2_(w, h, xdpi, ydpi),\
  148.     offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
  149.     std_device_part3_()
  150.  
  151. #define std_device_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)\
  152.     std_device_full_body_type(dtype, pprocs, dname, 0, w, h, xdpi, ydpi,\
  153.         ncomp, depth, mg, mc, dg, dc, xoff, yoff, lm, bm, rm, tm)
  154.  
  155. #define std_device_dci_alpha_type_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, ta, ga)\
  156.     std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
  157.     dci_alpha_values(ncomp, depth, mg, mc, dg, dc, ta, ga),\
  158.     std_device_part2_(w, h, xdpi, ydpi),\
  159.     offset_margin_values(0, 0, 0, 0, 0, 0),\
  160.     std_device_part3_()
  161.  
  162. #define std_device_dci_type_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)\
  163.     std_device_dci_alpha_type_body(dtype, pprocs, dname, stype, w, h,\
  164.       xdpi, ydpi, ncomp, depth, mg, mc, dg, dc, 1, 1)
  165.  
  166. #define std_device_dci_body(dtype, pprocs, dname, w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)\
  167.     std_device_dci_type_body(dtype, pprocs, dname, 0,\
  168.       w, h, xdpi, ydpi, ncomp, depth, mg, mc, dg, dc)
  169.  
  170. #define std_device_color_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, max_value, dither, xoff, yoff, lm, bm, rm, tm)\
  171.     std_device_part1_(dtype, pprocs, dname, 0, open_init_closed),\
  172.     dci_color(depth, max_value, dither),\
  173.     std_device_part2_(w, h, xdpi, ydpi),\
  174.     offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
  175.     std_device_part3_()
  176.  
  177. #define std_device_color_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, max_value, dither)\
  178.     std_device_color_full_body(dtype, pprocs, dname,\
  179.       w, h, xdpi, ydpi,\
  180.       depth, max_value, dither,\
  181.       0, 0, 0, 0, 0, 0)
  182.  
  183. #define std_device_color_stype_body(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, depth, max_value, dither)\
  184.     std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
  185.     dci_color(depth, max_value, dither),\
  186.     std_device_part2_(w, h, xdpi, ydpi),\
  187.     offset_margin_values(0, 0, 0, 0, 0, 0),\
  188.     std_device_part3_()
  189.  
  190. #define std_device_std_color_full_body_type(dtype, pprocs, dname, stype, w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)\
  191.     std_device_part1_(dtype, pprocs, dname, stype, open_init_closed),\
  192.     dci_std_color(depth),\
  193.     std_device_part2_(w, h, xdpi, ydpi),\
  194.     offset_margin_values(xoff, yoff, lm, bm, rm, tm),\
  195.     std_device_part3_()
  196.  
  197. #define std_device_std_color_full_body(dtype, pprocs, dname, w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)\
  198.     std_device_std_color_full_body_type(dtype, pprocs, dname, 0,\
  199.         w, h, xdpi, ydpi, depth, xoff, yoff, lm, bm, rm, tm)
  200.  
  201. /* ---------------- Default implementations ---------------- */
  202.  
  203. /* Default implementations of optional procedures. */
  204. /* Note that the default map_xxx_color routines assume white_on_black. */
  205. dev_proc_open_device(gx_default_open_device);
  206. dev_proc_get_initial_matrix(gx_default_get_initial_matrix);
  207. dev_proc_get_initial_matrix(gx_upright_get_initial_matrix);
  208. dev_proc_sync_output(gx_default_sync_output);
  209. dev_proc_output_page(gx_default_output_page);
  210. dev_proc_close_device(gx_default_close_device);
  211. dev_proc_map_rgb_color(gx_default_w_b_map_rgb_color);
  212. dev_proc_map_color_rgb(gx_default_w_b_map_color_rgb);
  213. #define gx_default_map_rgb_color gx_default_w_b_map_rgb_color
  214. #define gx_default_map_color_rgb gx_default_w_b_map_color_rgb
  215. dev_proc_tile_rectangle(gx_default_tile_rectangle);
  216. dev_proc_copy_mono(gx_default_copy_mono);
  217. dev_proc_copy_color(gx_default_copy_color);
  218. dev_proc_draw_line(gx_default_draw_line);
  219. dev_proc_get_bits(gx_no_get_bits);    /* gives error */
  220. dev_proc_get_bits(gx_default_get_bits);
  221. dev_proc_get_params(gx_default_get_params);
  222. dev_proc_put_params(gx_default_put_params);
  223. dev_proc_map_cmyk_color(gx_default_map_cmyk_color);
  224. dev_proc_get_xfont_procs(gx_default_get_xfont_procs);
  225. dev_proc_get_xfont_device(gx_default_get_xfont_device);
  226. dev_proc_map_rgb_alpha_color(gx_default_map_rgb_alpha_color);
  227. dev_proc_get_page_device(gx_default_get_page_device);    /* returns NULL */
  228. dev_proc_get_page_device(gx_page_device_get_page_device);    /* returns dev */
  229. dev_proc_get_alpha_bits(gx_default_get_alpha_bits);
  230. dev_proc_copy_alpha(gx_no_copy_alpha);    /* gives error */
  231. dev_proc_copy_alpha(gx_default_copy_alpha);
  232. dev_proc_get_band(gx_default_get_band);
  233. dev_proc_copy_rop(gx_no_copy_rop);    /* gives error */
  234. dev_proc_copy_rop(gx_default_copy_rop);
  235. dev_proc_fill_path(gx_default_fill_path);
  236. dev_proc_stroke_path(gx_default_stroke_path);
  237. dev_proc_fill_mask(gx_default_fill_mask);
  238. dev_proc_fill_trapezoid(gx_default_fill_trapezoid);
  239. dev_proc_fill_parallelogram(gx_default_fill_parallelogram);
  240. dev_proc_fill_triangle(gx_default_fill_triangle);
  241. dev_proc_draw_thin_line(gx_default_draw_thin_line);
  242. dev_proc_begin_image(gx_default_begin_image);
  243. dev_proc_image_data(gx_default_image_data);
  244. dev_proc_end_image(gx_default_end_image);
  245. dev_proc_strip_tile_rectangle(gx_default_strip_tile_rectangle);
  246. dev_proc_strip_copy_rop(gx_no_strip_copy_rop);    /* gives error */
  247. dev_proc_strip_copy_rop(gx_default_strip_copy_rop);
  248. dev_proc_get_clipping_box(gx_default_get_clipping_box);
  249. dev_proc_get_clipping_box(gx_get_largest_clipping_box);
  250. dev_proc_begin_typed_image(gx_default_begin_typed_image);
  251. dev_proc_get_bits_rectangle(gx_no_get_bits_rectangle);    /* gives error */
  252. dev_proc_get_bits_rectangle(gx_default_get_bits_rectangle);
  253. dev_proc_map_color_rgb_alpha(gx_default_map_color_rgb_alpha);
  254. dev_proc_create_compositor(gx_no_create_compositor);
  255. /* default is for ordinary "leaf" devices, null is for */
  256. /* devices that only care about coverage and not contents. */
  257. dev_proc_create_compositor(gx_default_create_compositor);
  258. dev_proc_create_compositor(gx_null_create_compositor);
  259. dev_proc_get_hardware_params(gx_default_get_hardware_params);
  260. dev_proc_text_begin(gx_default_text_begin);
  261. dev_proc_finish_copydevice(gx_default_finish_copydevice);
  262. /* BACKWARD COMPATIBILITY */
  263. #define gx_non_imaging_create_compositor gx_null_create_compositor
  264.  
  265. /* Color mapping routines for black-on-white, gray scale, true RGB, */
  266. /* true CMYK, and 1-bit CMYK color. */
  267. dev_proc_map_rgb_color(gx_default_b_w_map_rgb_color);
  268. dev_proc_map_color_rgb(gx_default_b_w_map_color_rgb);
  269. dev_proc_map_rgb_color(gx_default_gray_map_rgb_color);
  270. dev_proc_map_color_rgb(gx_default_gray_map_color_rgb);
  271. dev_proc_map_color_rgb(gx_default_rgb_map_color_rgb);
  272. #define gx_default_cmyk_map_cmyk_color cmyk_8bit_map_cmyk_color /*see below*/
  273. /*
  274.  * The following are defined as "standard" color mapping procedures
  275.  * that can be propagated through device pipelines and that color
  276.  * processing code can test for.
  277.  */
  278. dev_proc_map_rgb_color(gx_default_rgb_map_rgb_color);
  279. dev_proc_map_cmyk_color(cmyk_1bit_map_cmyk_color);
  280. dev_proc_map_color_rgb(cmyk_1bit_map_color_rgb);
  281. dev_proc_map_cmyk_color(cmyk_8bit_map_cmyk_color);
  282. dev_proc_map_color_rgb(cmyk_8bit_map_color_rgb);
  283.  
  284. /* Default implementations for forwarding devices */
  285. dev_proc_get_initial_matrix(gx_forward_get_initial_matrix);
  286. dev_proc_sync_output(gx_forward_sync_output);
  287. dev_proc_output_page(gx_forward_output_page);
  288. dev_proc_map_rgb_color(gx_forward_map_rgb_color);
  289. dev_proc_map_color_rgb(gx_forward_map_color_rgb);
  290. dev_proc_fill_rectangle(gx_forward_fill_rectangle);
  291. dev_proc_tile_rectangle(gx_forward_tile_rectangle);
  292. dev_proc_copy_mono(gx_forward_copy_mono);
  293. dev_proc_copy_color(gx_forward_copy_color);
  294. dev_proc_get_bits(gx_forward_get_bits);
  295. dev_proc_get_params(gx_forward_get_params);
  296. dev_proc_put_params(gx_forward_put_params);
  297. dev_proc_map_cmyk_color(gx_forward_map_cmyk_color);
  298. dev_proc_get_xfont_procs(gx_forward_get_xfont_procs);
  299. dev_proc_get_xfont_device(gx_forward_get_xfont_device);
  300. dev_proc_map_rgb_alpha_color(gx_forward_map_rgb_alpha_color);
  301. dev_proc_get_page_device(gx_forward_get_page_device);
  302. #define gx_forward_get_alpha_bits gx_default_get_alpha_bits
  303. dev_proc_copy_alpha(gx_forward_copy_alpha);
  304. dev_proc_get_band(gx_forward_get_band);
  305. dev_proc_copy_rop(gx_forward_copy_rop);
  306. dev_proc_fill_path(gx_forward_fill_path);
  307. dev_proc_stroke_path(gx_forward_stroke_path);
  308. dev_proc_fill_mask(gx_forward_fill_mask);
  309. dev_proc_fill_trapezoid(gx_forward_fill_trapezoid);
  310. dev_proc_fill_parallelogram(gx_forward_fill_parallelogram);
  311. dev_proc_fill_triangle(gx_forward_fill_triangle);
  312. dev_proc_draw_thin_line(gx_forward_draw_thin_line);
  313. dev_proc_begin_image(gx_forward_begin_image);
  314. #define gx_forward_image_data gx_default_image_data
  315. #define gx_forward_end_image gx_default_end_image
  316. dev_proc_strip_tile_rectangle(gx_forward_strip_tile_rectangle);
  317. dev_proc_strip_copy_rop(gx_forward_strip_copy_rop);
  318. dev_proc_get_clipping_box(gx_forward_get_clipping_box);
  319. dev_proc_begin_typed_image(gx_forward_begin_typed_image);
  320. dev_proc_get_bits_rectangle(gx_forward_get_bits_rectangle);
  321. dev_proc_map_color_rgb_alpha(gx_forward_map_color_rgb_alpha);
  322. /* There is no forward_create_compositor (see Drivers.htm). */
  323. dev_proc_get_hardware_params(gx_forward_get_hardware_params);
  324. dev_proc_text_begin(gx_forward_text_begin);
  325.  
  326. /* ---------------- Implementation utilities ---------------- */
  327.  
  328. /* Convert the device procedures to the proper form (see above). */
  329. void gx_device_set_procs(P1(gx_device *));
  330.  
  331. /* Fill in defaulted procedures in a device procedure record. */
  332. void gx_device_fill_in_procs(P1(gx_device *));
  333. void gx_device_forward_fill_in_procs(P1(gx_device_forward *));
  334.  
  335. /* Forward the color mapping procedures from a device to its target. */
  336. void gx_device_forward_color_procs(P1(gx_device_forward *));
  337.  
  338. /*
  339.  * Copy the color mapping procedures from the target if they are
  340.  * standard ones (saving a level of procedure call at mapping time).
  341.  */
  342. void gx_device_copy_color_procs(P2(gx_device *dev, const gx_device *target));
  343.  
  344. /* Get the black and white pixel values of a device. */
  345. gx_color_index gx_device_black(P1(gx_device *dev));
  346. #define gx_device_black_inline(dev)\
  347.   ((dev)->cached_colors.black != gx_no_color_index ?\
  348.    gx_device_black(dev) : (dev)->cached_colors.black)
  349. gx_color_index gx_device_white(P1(gx_device *dev));
  350. #define gx_device_white_inline(dev)\
  351.   ((dev)->cached_colors.white != gx_no_color_index ?\
  352.    gx_device_white(dev) : (dev)->cached_colors.white)
  353.  
  354. /* Clear the black/white pixel cache. */
  355. void gx_device_decache_colors(P1(gx_device *dev));
  356.  
  357. /*
  358.  * Copy the color-related device parameters back from the target:
  359.  * color_info and color mapping procedures.
  360.  */
  361. void gx_device_copy_color_params(P2(gx_device *dev, const gx_device *target));
  362.  
  363. /*
  364.  * Copy device parameters back from a target.  This copies all standard
  365.  * parameters related to page size and resolution, plus color_info
  366.  * and (if appropriate) color mapping procedures.
  367.  */
  368. void gx_device_copy_params(P2(gx_device *dev, const gx_device *target));
  369.  
  370. /*
  371.  * Parse the output file name for a device, recognizing "-" and "|command",
  372.  * and also detecting and validating any %nnd format for inserting the
  373.  * page count.  If a format is present, store a pointer to its last
  374.  * character in *pfmt, otherwise store 0 there.  Note that an empty name
  375.  * is currently allowed.
  376.  */
  377. int gx_parse_output_file_name(P4(gs_parsed_file_name_t *pfn,
  378.                  const char **pfmt, const char *fname,
  379.                  uint len));
  380.  
  381. /*
  382.  * Open the output file for a device.  Note that if the file name is empty,
  383.  * it may be replaced with the name of a scratch file.
  384.  */
  385. int gx_device_open_output_file(P5(const gx_device * dev, char *fname,
  386.                   bool binary, bool positionable,
  387.                   FILE ** pfile));
  388.  
  389. /* Close the output file for a device. */
  390. int gx_device_close_output_file(P3(const gx_device * dev, const char *fname,
  391.                    FILE *file));
  392.  
  393. /*
  394.  * Determine whether a given device needs to halftone.  Eventually this
  395.  * should take an imager state as an additional argument.
  396.  */
  397. #define gx_device_must_halftone(dev)\
  398.   ((gx_device_has_color(dev) ? (dev)->color_info.max_color :\
  399.     (dev)->color_info.max_gray) < 31)
  400. #define gx_color_device_must_halftone(dev)\
  401.   ((dev)->color_info.max_gray < 31)
  402.  
  403. /*
  404.  * Do generic work for output_page.  All output_page procedures must call
  405.  * this as the last thing they do, unless an error has occurred earlier.
  406.  */
  407. dev_proc_output_page(gx_finish_output_page);
  408.  
  409. /*
  410.  * Device procedures that draw into rectangles need to clip the coordinates
  411.  * to the rectangle ((0,0),(dev->width,dev->height)).  The following macros
  412.  * do the clipping.  They assume that the arguments of the procedure are
  413.  * named dev, x, y, w, and h, and may modify the arguments (other than dev).
  414.  *
  415.  * For procedures that fill a region, dev, x, y, w, and h are the only
  416.  * relevant arguments.  For procedures that copy bitmaps, see below.
  417.  *
  418.  * The following group of macros for region-filling procedures clips
  419.  * specific edges of the supplied rectangle, as indicated by the macro name.
  420.  */
  421. #define fit_fill_xy(dev, x, y, w, h)\
  422.   BEGIN\
  423.     if ( (x | y) < 0 ) {\
  424.       if ( x < 0 )\
  425.         w += x, x = 0;\
  426.       if ( y < 0 )\
  427.         h += y, y = 0;\
  428.     }\
  429.   END
  430. #define fit_fill_y(dev, y, h)\
  431.   BEGIN\
  432.     if ( y < 0 )\
  433.       h += y, y = 0;\
  434.   END
  435. #define fit_fill_w(dev, x, w)\
  436.   BEGIN\
  437.     if ( w > (dev)->width - x )\
  438.       w = (dev)->width - x;\
  439.   END
  440. #define fit_fill_h(dev, y, h)\
  441.   BEGIN\
  442.     if ( h > (dev)->height - y )\
  443.       h = (dev)->height - y;\
  444.   END
  445. #define fit_fill_xywh(dev, x, y, w, h)\
  446.   BEGIN\
  447.     fit_fill_xy(dev, x, y, w, h);\
  448.     fit_fill_w(dev, x, w);\
  449.     fit_fill_h(dev, y, h);\
  450.   END
  451. /*
  452.  * Clip all edges, and return from the procedure if the result is empty.
  453.  */
  454. #define fit_fill(dev, x, y, w, h)\
  455.   BEGIN\
  456.     fit_fill_xywh(dev, x, y, w, h);\
  457.     if ( w <= 0 || h <= 0 )\
  458.       return 0;\
  459.   END
  460.  
  461. /*
  462.  * For driver procedures that copy bitmaps (e.g., copy_mono, copy_color),
  463.  * clipping the destination region also may require adjusting the pointer to
  464.  * the source data.  In addition to dev, x, y, w, and h, the clipping macros
  465.  * for these procedures reference data, data_x, raster, and id; they may
  466.  * modify the values of data, data_x, and id.
  467.  *
  468.  * Clip the edges indicated by the macro name.
  469.  */
  470. #define fit_copy_xyw(dev, data, data_x, raster, id, x, y, w, h)\
  471.   BEGIN\
  472.     if ( (x | y) < 0 ) {\
  473.       if ( x < 0 )\
  474.         w += x, data_x -= x, x = 0;\
  475.       if ( y < 0 )\
  476.         h += y, data -= y * raster, id = gx_no_bitmap_id, y = 0;\
  477.     }\
  478.     if ( w > (dev)->width - x )\
  479.       w = (dev)->width - x;\
  480.   END
  481. /*
  482.  * Clip all edges, and return from the procedure if the result is empty.
  483.  */
  484. #define fit_copy(dev, data, data_x, raster, id, x, y, w, h)\
  485.   BEGIN\
  486.     fit_copy_xyw(dev, data, data_x, raster, id, x, y, w, h);\
  487.     if ( h > (dev)->height - y )\
  488.       h = (dev)->height - y;\
  489.     if ( w <= 0 || h <= 0 )\
  490.       return 0;\
  491.   END
  492.  
  493. /* ---------------- Media parameters ---------------- */
  494.  
  495. /* Define the InputAttributes and OutputAttributes of a device. */
  496. /* The device get_params procedure would call these. */
  497.  
  498. typedef struct gdev_input_media_s {
  499.     float PageSize[4];        /* nota bene */
  500.     const char *MediaColor;
  501.     float MediaWeight;
  502.     const char *MediaType;
  503. } gdev_input_media_t;
  504.  
  505. #define gdev_input_media_default_values { 0, 0, 0, 0 }, 0, 0, 0
  506. extern const gdev_input_media_t gdev_input_media_default;
  507.  
  508. void gdev_input_media_init(P1(gdev_input_media_t * pim));
  509.  
  510. int gdev_begin_input_media(P3(gs_param_list * mlist, gs_param_dict * pdict,
  511.                   int count));
  512.  
  513. int gdev_write_input_page_size(P4(int index, gs_param_dict * pdict,
  514.                 floatp width_points, floatp height_points));
  515.  
  516. int gdev_write_input_media(P3(int index, gs_param_dict * pdict,
  517.                   const gdev_input_media_t * pim));
  518.  
  519. int gdev_end_input_media(P2(gs_param_list * mlist, gs_param_dict * pdict));
  520.  
  521. typedef struct gdev_output_media_s {
  522.     const char *OutputType;
  523. } gdev_output_media_t;
  524.  
  525. #define gdev_output_media_default_values 0
  526. extern const gdev_output_media_t gdev_output_media_default;
  527.  
  528. int gdev_begin_output_media(P3(gs_param_list * mlist, gs_param_dict * pdict,
  529.                    int count));
  530.  
  531. int gdev_write_output_media(P3(int index, gs_param_dict * pdict,
  532.                    const gdev_output_media_t * pom));
  533.  
  534. int gdev_end_output_media(P2(gs_param_list * mlist, gs_param_dict * pdict));
  535.  
  536. #endif /* gxdevice_INCLUDED */
  537.